home *** CD-ROM | disk | FTP | other *** search
/ 600 Games / 600games.iso / Nave / Cosmic Defender.swf / scripts / frame_10 / DoAction.as
Encoding:
Text File  |  2006-06-13  |  16.7 KB  |  541 lines

  1. function Swarmer()
  2. {
  3. }
  4. function Pod()
  5. {
  6. }
  7. function Bomber()
  8. {
  9. }
  10. function Baiter()
  11. {
  12. }
  13. function Mutant()
  14. {
  15. }
  16. function Lander()
  17. {
  18. }
  19. function Man()
  20. {
  21. }
  22. _root.tip_array = new Array("Tip: Press \'P\' to pause the game and access the menu whilst the game is playing.","Tip: Press \'S\' to activate the smart bomb and destroy everything on the screen (you have limited bombs).","Tip: Press \'D\' to activate hyperspace and get out of trouble (you have unlimited hyperspaces).","Tip: Keep an eye on the radar for alien abductions.  If they get to the top they become mutants.","Tip: Press and hold down the \'A\' button for constant fire.","Tip: Catch falling comrades mid-air and land them safely for maximum points.");
  23. _root.extra_points = 7500;
  24. _root.extra_bombs = 5000;
  25. _root.enemies_to_kill = 10;
  26. _root.max_enemies = 10;
  27. _root.en_shot_speed = 1;
  28. _root.en_appear_time = 15;
  29. _root.sound_on = true;
  30. _root.splash_music = new Sound(this);
  31. _root.splash_music.attachSound("splash_music");
  32. _root.extra_life_sfx = new Sound(this);
  33. _root.extra_life_sfx.attachSound("extra_life_sfx");
  34. _root.blast_sfx = new Sound(this);
  35. _root.blast_sfx.attachSound("blast_sfx");
  36. _root.hyperjump = new Sound(this);
  37. _root.hyperjump.attachSound("hyper_sfx");
  38. _root.ship_appear = new Sound();
  39. _root.ship_appear.attachSound("ship_appear_sfx");
  40. _root.en_shot_sfx = new Sound();
  41. _root.en_shot_sfx.attachSound("enemy_shot_sfx");
  42. _root.pl_shot_sfx = new Sound();
  43. _root.pl_shot_sfx.attachSound("pl_shot_sfx");
  44. _root.smart_sfx = new Sound();
  45. _root.smart_sfx.attachSound("smart_bomb_sfx");
  46. _root.man_captured_sfx = new Sound();
  47. _root.man_captured_sfx.attachSound("man_captured_sfx");
  48. _root.man_taken_sfx = new Sound();
  49. _root.man_taken_sfx.attachSound("man_taken_sfx");
  50. Swarmer.prototype = new MovieClip();
  51. Swarmer.prototype.onLoad = function()
  52. {
  53.    _root.enemies_on += 1;
  54.    _root.locator.attachMovie("radar_dot",this._name,Number(this._name.slice(5)) + 30);
  55.    eval("_root.locator." + this._name).gotoAndStop(7);
  56.    if(this.dx < 0)
  57.    {
  58.       this._xscale = -100;
  59.    }
  60. };
  61. Swarmer.prototype.Destroy = function()
  62. {
  63.    removeMovieClip(eval("_root.locator." + this._name));
  64.    _root.AttachBang(this._x,this._y);
  65.    _root.Scoring(this._x,this._y,150);
  66.    _root.CheckLevelFin();
  67.    removeMovieClip(this);
  68. };
  69. Swarmer.prototype.onEnterFrame = function()
  70. {
  71.    var _loc1_ = this;
  72.    var _loc2_ = _root;
  73.    if(_loc2_.player_on && !_loc2_.paused)
  74.    {
  75.       if(_loc1_.hitTest(_loc2_.ship_0.hot_spot_en))
  76.       {
  77.          _loc2_.PlayerHitted();
  78.       }
  79.       if(Math.random() < 0.02 * _loc2_.en_shooting)
  80.       {
  81.          _loc2_.EnShooting(_loc1_.x,_loc1_._y,_loc1_._x);
  82.       }
  83.       _loc1_.y1 = _loc1_._y + _loc1_.dy * _loc2_.enemy_speed;
  84.       if(_loc1_.y1 > 330 || _loc1_.y1 < 80 || Math.random() < 0.01)
  85.       {
  86.          _loc1_.dy = - _loc1_.dy;
  87.       }
  88.       else
  89.       {
  90.          _loc1_._y = _loc1_.y1;
  91.       }
  92.       _loc1_.x = _loc2_.ToNewX(_loc1_.x,_loc1_.dx * _loc2_.enemy_speed);
  93.       _loc1_._x = _loc2_.ToGlobal(_loc1_.x);
  94.    }
  95. };
  96. Object.registerClass("swarmer",Swarmer);
  97. Pod.prototype = new MovieClip();
  98. Pod.prototype.onLoad = function()
  99. {
  100.    _root.enemies_on += 1;
  101.    _root.locator.attachMovie("radar_dot",this._name,Number(this._name.slice(5)) + 30);
  102.    eval("_root.locator." + this._name).gotoAndStop(6);
  103.    this.dx = Math.random() >= 0.5 ? -4 * _root.enemy_speed : 4 * _root.enemy_speed;
  104.    this.dy = Math.random() >= 0.5 ? -1 * _root.enemy_speed : 1 * _root.enemy_speed;
  105. };
  106. Pod.prototype.Destroy = function(bang)
  107. {
  108.    if(!bang)
  109.    {
  110.       this.swarmers = 4;
  111.       s = 1;
  112.       while(s < 16)
  113.       {
  114.          if(!_root.EnemyAr[s])
  115.          {
  116.             _root.EnemyAr[s] = true;
  117.             _root.attachMovie("swarmer","ship_" + s,s + 30);
  118.             this.ship = eval("_root.ship_" + s);
  119.             this.ship.x = this.x;
  120.             this.ship._y = this._y;
  121.             this.ship.dx = this.dx * 1.5;
  122.             this.ship.dy = (this.swarmers - 3) * 2 + 1;
  123.             this.swarmers -= 1;
  124.             if(this.swarmers == 0)
  125.             {
  126.                s = 16;
  127.             }
  128.          }
  129.          s++;
  130.       }
  131.    }
  132.    removeMovieClip(eval("_root.locator." + this._name));
  133.    _root.AttachBang(this._x,this._y);
  134.    _root.Scoring(this._x,this._y,1000);
  135.    _root.CheckLevelFin();
  136.    removeMovieClip(this);
  137. };
  138. Pod.prototype.onEnterFrame = function()
  139. {
  140.    var _loc1_ = this;
  141.    var _loc2_ = _root;
  142.    if(_loc2_.player_on && !_loc2_.paused)
  143.    {
  144.       if(_loc1_.hitTest(_loc2_.ship_0.hot_spot_en))
  145.       {
  146.          _loc2_.PlayerHitted();
  147.       }
  148.       if(Math.random() < 0.02 * _loc2_.en_shooting)
  149.       {
  150.          _loc2_.EnShooting(_loc1_.x,_loc1_._y,_loc1_._x);
  151.       }
  152.       _loc1_.y1 = _loc1_._y + _loc1_.dy;
  153.       if(_loc1_.y1 > 330 || _loc1_.y1 < 80 || Math.random() < 0.01)
  154.       {
  155.          _loc1_.dy = - _loc1_.dy;
  156.       }
  157.       else
  158.       {
  159.          _loc1_._y = _loc1_.y1;
  160.       }
  161.       _loc1_.x = _loc2_.ToNewX(_loc1_.x,_loc1_.dx);
  162.       _loc1_._x = _loc2_.ToGlobal(_loc1_.x);
  163.    }
  164. };
  165. Object.registerClass("pod",Pod);
  166. Bomber.prototype = new MovieClip();
  167. Bomber.prototype.onLoad = function()
  168. {
  169.    _root.enemies_on += 1;
  170.    _root.locator.attachMovie("radar_dot",this._name,Number(this._name.slice(5)) + 30);
  171.    eval("_root.locator." + this._name).gotoAndStop(5);
  172.    this.dx = Math.random() >= 0.5 ? -4 * _root.enemy_speed : 4 * _root.enemy_speed;
  173.    this.dy = Math.random() >= 0.5 ? -1 * _root.enemy_speed : 1 * _root.enemy_speed;
  174.    this.timr = 15;
  175.    this.mines = 4;
  176. };
  177. Bomber.prototype.Destroy = function()
  178. {
  179.    removeMovieClip(eval("_root.locator." + this._name));
  180.    _root.AttachBang(this._x,this._y);
  181.    _root.Scoring(this._x,this._y,250);
  182.    _root.CheckLevelFin();
  183.    removeMovieClip(this);
  184. };
  185. Bomber.prototype.onEnterFrame = function()
  186. {
  187.    if(_root.player_on && !_root.paused)
  188.    {
  189.       if(this.hitTest(_root.ship_0.hot_spot_en))
  190.       {
  191.          _root.PlayerHitted();
  192.       }
  193.       if(this.timr <= 0 && this.mines > 0)
  194.       {
  195.          this.timr = 15;
  196.          this.mines -= 1;
  197.          if(this._x < 700)
  198.          {
  199.             _root.attachMovie("mine","mine_" + _root.mines_count,_root.mines_count);
  200.             eval("_root.mine_" + _root.mines_count).x = this.x;
  201.             eval("_root.mine_" + _root.mines_count)._y = this._y;
  202.             _root.mines_count += 1;
  203.             if(_root.mines_count == 20)
  204.             {
  205.                _root.mines_count = 0;
  206.             }
  207.          }
  208.       }
  209.       else
  210.       {
  211.          this.timr -= 1;
  212.       }
  213.       this.y1 = this._y + this.dy;
  214.       if(this.y1 > 330 || this.y1 < 80)
  215.       {
  216.          if(this.mines <= 0)
  217.          {
  218.             this.timr = 15;
  219.             this.mines = 4;
  220.          }
  221.          this.dy = - this.dy;
  222.       }
  223.       else
  224.       {
  225.          this._y = this.y1;
  226.       }
  227.       this.x = _root.ToNewX(this.x,this.dx);
  228.       this._x = _root.ToGlobal(this.x);
  229.    }
  230. };
  231. Object.registerClass("bomber",Bomber);
  232. Baiter.prototype = new MovieClip();
  233. Baiter.prototype.onLoad = function()
  234. {
  235.    _root.enemies_on += 1;
  236.    _root.locator.attachMovie("radar_dot",this._name,Number(this._name.slice(5)) + 30);
  237.    eval("_root.locator." + this._name).gotoAndStop(4);
  238.    this.to_x = Math.random() * _root.x_dimension;
  239.    this.y_init = this._y;
  240.    this.sinus = 0;
  241. };
  242. Baiter.prototype.Destroy = function()
  243. {
  244.    removeMovieClip(eval("_root.locator." + this._name));
  245.    _root.AttachBang(this._x,this._y);
  246.    _root.Scoring(this._x,this._y,200);
  247.    _root.CheckLevelFin();
  248.    removeMovieClip(this);
  249. };
  250. Baiter.prototype.onEnterFrame = function()
  251. {
  252.    var _loc1_ = this;
  253.    var _loc2_ = _root;
  254.    if(_loc2_.player_on && !_loc2_.paused)
  255.    {
  256.       if(_loc1_.hitTest(_loc2_.ship_0.hot_spot_en))
  257.       {
  258.          _loc2_.PlayerHitted();
  259.       }
  260.       _loc1_.distance = _loc1_.to_x - _loc1_.x;
  261.       if(Math.abs(_loc1_.distance) < 40)
  262.       {
  263.          _loc1_.to_x = Math.random() * _loc2_.x_dimension;
  264.          _loc1_.y_amp = 2 * (Math.random() * 10);
  265.       }
  266.       _loc1_.dx = _loc1_.to_x <= _loc1_.x ? -14 * _loc2_.enemy_speed : 14 * _loc2_.enemy_speed;
  267.       _loc1_.x = _loc2_.ToNewX(_loc1_.x,_loc1_.dx);
  268.       _loc1_._y = _loc1_.y_init + Math.sin(_loc1_.sinus) * 20 * _loc2_.enemy_speed;
  269.       _loc1_.sinus += 0.1;
  270.       _loc1_._x = _loc2_.ToGlobal(_loc1_.x);
  271.       if(Math.random() < 0.04 * _loc2_.en_shooting)
  272.       {
  273.          _loc2_.EnShooting(_loc1_.x,_loc1_._y,_loc1_._x);
  274.       }
  275.    }
  276. };
  277. Object.registerClass("baiter",Baiter);
  278. Mutant.prototype = new MovieClip();
  279. Mutant.prototype.onLoad = function()
  280. {
  281.    _root.enemies_on += 1;
  282.    _root.locator.attachMovie("radar_dot",this._name,Number(this._name.slice(5)) + 30);
  283.    eval("_root.locator." + this._name).gotoAndStop(2);
  284.    this.sinus = 0;
  285. };
  286. Mutant.prototype.Destroy = function()
  287. {
  288.    removeMovieClip(eval("_root.locator." + this._name));
  289.    _root.AttachBang(this._x,this._y);
  290.    _root.Scoring(this._x,this._y,150);
  291.    _root.CheckLevelFin();
  292.    removeMovieClip(this);
  293. };
  294. Mutant.prototype.onEnterFrame = function()
  295. {
  296.    var _loc1_ = this;
  297.    var _loc2_ = _root;
  298.    if(_loc2_.player_on && !_loc2_.paused)
  299.    {
  300.       if(_loc1_.hitTest(_loc2_.ship_0.hot_spot_en))
  301.       {
  302.          _loc2_.PlayerHitted();
  303.       }
  304.       _loc1_.x_incr = _loc2_.ship_0._x - _loc1_._x;
  305.       _loc1_.ang = Math.atan2(_loc2_.ship_0._y - _loc1_._y,_loc1_.x_incr);
  306.       _loc1_._y += Math.sin(_loc1_.ang) * 8 * _loc2_.enemy_speed + Math.sin(_loc1_.sinus) * 5;
  307.       _loc1_.sinus += 0.2;
  308.       _loc1_.dx = Math.cos(_loc1_.ang) * 8 * _loc2_.enemy_speed;
  309.       if(Math.abs(_loc1_.x_incr) > _loc2_.x_dimension / 2)
  310.       {
  311.          _loc1_.dx = - _loc1_.dx;
  312.       }
  313.       _loc1_.x = _loc2_.ToNewX(_loc1_.x,_loc1_.dx);
  314.       _loc1_._x = _loc2_.ToGlobal(_loc1_.x);
  315.       if(Math.random() < 0.02 * _loc2_.en_shooting)
  316.       {
  317.          _loc2_.EnShooting(_loc1_.x,_loc1_._y,_loc1_._x);
  318.       }
  319.    }
  320. };
  321. Object.registerClass("mutant",Mutant);
  322. Lander.prototype = new MovieClip();
  323. Lander.prototype.onLoad = function()
  324. {
  325.    _root.enemies_on += 1;
  326.    this.action = 0;
  327.    this.dx = Math.random() >= 0.5 ? 4 * _root.enemy_speed : -4 * _root.enemy_speed;
  328.    this.dy = (Math.random() * 4 - 2) * _root.enemy_speed;
  329.    _root.locator.attachMovie("radar_dot",this._name,Number(this._name.slice(5)) + 30);
  330.    eval("_root.locator." + this._name).gotoAndStop(3);
  331. };
  332. Lander.prototype.Destroy = function()
  333. {
  334.    this.victim.action = 2;
  335.    this.action = 0;
  336.    _root.ShowMessage(false);
  337.    removeMovieClip(eval("_root.locator." + this._name));
  338.    _root.AttachBang(this._x,this._y);
  339.    _root.Scoring(this._x,this._y,150);
  340.    _root.CheckLevelFin();
  341.    removeMovieClip(this);
  342. };
  343. Lander.prototype.onEnterFrame = function()
  344. {
  345.    if(_root.player_on && !_root.paused)
  346.    {
  347.       if(this.hitTest(_root.ship_0.hot_spot_en))
  348.       {
  349.          _root.PlayerHitted();
  350.       }
  351.       switch(this.action)
  352.       {
  353.          case 0:
  354.             this.victim = undefined;
  355.             this.y1 = this._y + this.dy;
  356.             if(this.y1 > 80 && this.y1 < 330)
  357.             {
  358.                this._y = this.y1;
  359.             }
  360.             if(Math.random() < 0.02)
  361.             {
  362.                this.dy = (Math.random() * 4 - 2) * _root.enemy_speed;
  363.                if(Math.random() < 0.5 * _root.en_shooting)
  364.                {
  365.                   _root.EnShooting(this.x,this._y,this._x);
  366.                }
  367.             }
  368.             if(Math.random() < 0.004 * _root.pick_up_man)
  369.             {
  370.                this.ind = Math.floor(Math.random() * 10) + 1;
  371.                this.victim = eval("_root.man_" + this.ind);
  372.                if(_root.AstroAr[this.ind] && this.victim.action == 0)
  373.                {
  374.                   _root.AstroAr[this.ind] = false;
  375.                   this.action = 1;
  376.                }
  377.             }
  378.             this.x = _root.ToNewX(this.x,this.dx);
  379.             this._x = _root.ToGlobal(this.x);
  380.             break;
  381.          case 1:
  382.             if(Math.random() < 0.01)
  383.             {
  384.                _root.EnShooting(this.x,this._y,this._x);
  385.             }
  386.             this.ang = Math.atan2(this.victim._y - 15 - this._y,this.victim.x - this.x);
  387.             this._y += Math.sin(this.ang) * 4 * _root.enemy_speed;
  388.             this.dx = Math.cos(this.ang) * 4 * _root.enemy_speed;
  389.             if(this.victim.action != 0)
  390.             {
  391.                this.action = 0;
  392.             }
  393.             if(this.hitTest(this.victim))
  394.             {
  395.                _root.ShowMessage(true);
  396.                this.action = 2;
  397.                this.victim.action = 1;
  398.                this.victim.x = this.x;
  399.                if(_root.sound_on)
  400.                {
  401.                   _root.man_captured_sfx.start(0,1);
  402.                }
  403.             }
  404.             this.x = _root.ToNewX(this.x,this.dx);
  405.             this._x = _root.ToGlobal(this.x);
  406.             break;
  407.          case 2:
  408.             this.x = _root.ToNewX(this.x,0);
  409.             this._x = _root.ToGlobal(this.x);
  410.             this._y -= 2 * _root.enemy_speed;
  411.             if(this.victim._y < 20)
  412.             {
  413.                this.action = 0;
  414.                _root.ShowMessage(false);
  415.                this.dx = Math.random() >= 0.5 ? 4 * _root.enemy_speed : -4 * _root.enemy_speed;
  416.             }
  417.             if(this._y <= 80)
  418.             {
  419.                removeMovieClip(eval("_root.locator." + this._name));
  420.                this.victim.Destroy();
  421.                _root.EnemyAr[Number(this._name.slice(5))] = false;
  422.                _root.enemies_on -= 1;
  423.                _root.EnemyAttach(2,false,this.x,this._y);
  424.                this.action = 0;
  425.                _root.ShowMessage(false);
  426.                removeMovieClip(this);
  427.             }
  428.       }
  429.    }
  430. };
  431. Object.registerClass("lander",Lander);
  432. Man.prototype = new MovieClip();
  433. Man.prototype.Destroy = function()
  434. {
  435.    if(this.action == 1)
  436.    {
  437.       _root.ShowMessage(false);
  438.    }
  439.    _root.max_astronauts -= 1;
  440.    _root.astronauts -= 1;
  441.    if(_root.astronauts <= 0)
  442.    {
  443.       _root.PlanetDestroy();
  444.    }
  445.    removeMovieClip(eval("_root.locator." + this._name));
  446.    _root.AttachBang(this._x,this._y);
  447.    removeMovieClip(this);
  448. };
  449. Man.prototype.onLoad = function()
  450. {
  451.    _root.astronauts += 1;
  452.    this.action = 0;
  453.    this.gotoAndPlay(Math.floor(Math.random() * 26));
  454.    if(Math.random() < 0.5)
  455.    {
  456.       this.dx = -0.3;
  457.    }
  458.    else
  459.    {
  460.       this.dx = 0.3;
  461.       this._xscale = -100;
  462.    }
  463.    this._y = 370;
  464.    this.x = Math.random() * _root.x_dimension;
  465.    _root.locator.attachMovie("radar_dot",this._name,2 + Number(this._name.slice(4)));
  466.    eval("_root.locator." + this._name).gotoAndStop(8);
  467. };
  468. Man.prototype.onEnterFrame = function()
  469. {
  470.    var _loc1_ = this;
  471.    var _loc2_ = _root;
  472.    if(!_loc2_.paused)
  473.    {
  474.       switch(_loc1_.action)
  475.       {
  476.          case 0:
  477.             if(_loc2_.player_on)
  478.             {
  479.                _loc1_.x = _loc2_.ToNewX(_loc1_.x,_loc1_.dx);
  480.             }
  481.             _loc1_._x = _loc2_.ToGlobal(_loc1_.x);
  482.             _loc1_.fall_from = 300;
  483.             break;
  484.          case 1:
  485.             if(_loc2_.player_on)
  486.             {
  487.                _loc1_.x = _loc2_.ToNewX(_loc1_.x,0);
  488.                _loc1_._x = _loc2_.ToGlobal(_loc1_.x);
  489.                _loc1_._y -= 2 * _loc2_.enemy_speed;
  490.                _loc1_.fall_from = _loc1_._y;
  491.                _loc1_.dy = 0;
  492.             }
  493.             break;
  494.          case 2:
  495.             if(_loc2_.player_on)
  496.             {
  497.                _loc1_.x = _loc2_.ToNewX(_loc1_.x,0);
  498.                _loc1_._x = _loc2_.ToGlobal(_loc1_.x);
  499.                _loc1_._y += _loc1_.dy;
  500.                _loc1_.dy += 0.05;
  501.                if(_loc1_.hitTest(_loc2_.ship_0))
  502.                {
  503.                   _loc2_.Scoring(_loc1_._x,_loc1_._y,500);
  504.                   _loc1_.action = 3;
  505.                   if(_loc2_.sound_on)
  506.                   {
  507.                      _loc2_.man_taken_sfx.start(0,1);
  508.                   }
  509.                }
  510.                if(_loc1_._y >= 370)
  511.                {
  512.                   if(_loc1_.fall_from < 260)
  513.                   {
  514.                      _loc1_.Destroy();
  515.                   }
  516.                   _loc2_.Scoring(_loc1_._x,_loc1_._y,250);
  517.                   _loc1_._y = 370;
  518.                   _loc1_.action = 0;
  519.                   _loc2_.AstroAr[Number(_loc1_._name.slice(4))] = true;
  520.                }
  521.             }
  522.             break;
  523.          case 3:
  524.             if(_loc2_.player_on)
  525.             {
  526.                _loc1_.x = _loc2_.ship_x + _loc2_.ship_0._x;
  527.                _loc1_._x = _loc2_.ship_0._x;
  528.                _loc1_._y = _loc2_.ship_0._y + 15;
  529.                if(_loc1_._y >= 365)
  530.                {
  531.                   _loc2_.Scoring(_loc1_._x,_loc1_._y,500);
  532.                   _loc1_._y = 370;
  533.                   _loc1_.action = 0;
  534.                   _loc2_.AstroAr[Number(_loc1_._name.slice(4))] = true;
  535.                }
  536.             }
  537.       }
  538.    }
  539. };
  540. Object.registerClass("man",Man);
  541.